<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../../vue.js"></script>
  </head>

  <body>
    <div id="app">
      <h1>{{person.name}}--{{person.age}}</h1>
      <button @click="person.age++">改变年龄</button>
      <hr />
      <button @click="isHot = !isHot">改变天气</button>
      <h1>今天的天气真{{isHot?"热":"冷"}}</h1>
      <img :src="url" alt="" />
    </div>
    <script>
      Vue.config.productionTip = false;
      const vm = new Vue({
        el: "#app",
        data() {
          return {
            isHot: true,
            url: "",
            person: {
              name: "laowang",
              age: 19,
            },
          };
        },
        watch: {
          isHot: {
            //开启立即监视
            immediate: true,
            handler(newValue, oldValue) {
              this.url = newValue ? "./re.webp" : "./leng.gif";
            },
          },
          person: {
            //开启深度监视,监视对象或数组的值
            deep: true,
            handler(newPer, oldPer) {
              console.log(newPer.age, oldPer.age);
              alert("你老了");
            },
          },
        },
      });
    </script>
  </body>
</html>
